//
//  WeddingCarDetailViewController.m
//  BaseProject
//
//  Created by 王洋 on 2021/5/10.
//  Copyright © 2021 王洋. All rights reserved.
//
#import "ZZLayout.h"
#import "LSTPopView.h"


#import "WeddingCarCartModel.h"

#import "IMBottomBubbleView.h"
#import "TIIMQuickReplyCardModel.h"
#import "StoreQuickReplyView.h"

#import "PackageDetailNaviView.h"
#import "WeddingCarDetailBottomView.h"

#import "ProductDetailNormalSectionView.h"
#import "ProductDetailEvaluationHeader.h"
#import "PackageDetailSectionHeader.h"
#import "WeddingCarDetailSectionView.h"

#import "ProductDetailSectionFooterView.h"



#import "PackageDetailBannerCell.h"
#import "WeddingCarDetailSKUCell.h"

#import "WeddingCarDetailServiceCell.h"
#import "WeddingCarDetailInfoCell.h"

#import "PackageDetailInfoShowCell.h"
#import "PackageDetailStoreInfoCell.h"
#import "WeddingCarDetailRecCell.h"
#import "WeddingCarDetailRecCell.h"

#import "WeddingCarDetailStepCell.h"

#import "PackageDetailRequest.h"

#import "PackageSKUView.h"

#import "ImageTextTableViewController.h"
#import "ServiceContentViewController.h"

#import "RelatedCasesViewController.h"
#import "ServiceContentViewController.h"

#import "SubmitCarOrderViewController.h"

#import "StoreDetailViewController.h"

#import "EvaluationDetailViewController.h"
#import "TT_ConversationDetailViewController.h"
#import "MessageCenterViewController.h"
#import "EvaluateListViewController.h"
#import "PromisePopViewController.h"
#import "TT_WebviewController.h"
//快问
#import "QuanYiViewController.h"

#import "WYXViewController.h"
#import "WeddingCarCartViewController.h"
#import "MessageCenterViewController.h"

#import "WeddingCarDetailViewController.h"

@interface WeddingCarDetailViewController ()
<UICollectionViewDelegate,
UICollectionViewDataSource,
ZZLayoutDelegate>

@property (nonatomic, strong) PackageDetailModule *model;

@property (nonatomic, strong) PackageDetailNaviView *naviView;
@property (nonatomic, strong) WeddingCarDetailBottomView *bottomView;
@property (nonatomic, strong) IMBottomBubbleView *bubbleView;

@property (nonatomic, strong) LSTPopView *popView;
@property (nonatomic, strong) PackageSKUView *skuView;

@property (nonatomic, strong) PackageDetailBannerCell *mediaCell;

@property (nonatomic, strong) UICollectionViewCell *serviceCell;
@property (nonatomic, strong) UICollectionViewCell *imageTextCell;
@property (nonatomic, strong) UICollectionViewCell *quanyiCell;

@property (nonatomic, assign) CGFloat serviceHeight;
@property (nonatomic, assign) CGFloat imageTextHeight;
@property (nonatomic, assign) CGFloat quanyiHeight;


@property (nonatomic, strong) WeddingCarCartModel *handleModel;

@property (nonatomic, strong) UICollectionView *collectionView;

@property (nonatomic, strong) ImageTextTableViewController *imageTextVC;

@property (nonatomic, strong) ServiceContentViewController *serviceVC;

@property (nonatomic, strong) QuanYiViewController *quanyiVC;

@property (nonatomic, strong) WeddingCarSpecModel *selModel;

//当前 显示状态   权益or collectionview
//快问
@property(nonatomic,strong)TIIMQuickReplyCardModel *quickReplyModel;
@property(nonatomic,strong)BaseAdjustButton *quickReplyButton;
@property(nonatomic,weak)StoreQuickReplyView *weakQuickReplyView;

@end

@implementation WeddingCarDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self request_packageDetail];
}

- (void)initView {
    
    self.navigationController.navigationBarHidden = YES;
    #if RT_INTERACTIVE_PUSH
        self.rt_navigationController.rt_enableInteractivePush = YES;
    #endif
    self.view.backgroundColor = UIColorHex(0xf7f7f7);
    
    [self.view addSubview:self.collectionView];

    [self.view addSubview:self.naviView];
    [self.view addSubview:self.bottomView];
    
    if (self.model.sellerModel.consultingStar.length > 0) {

        CGFloat width = [Utilities getStringWidthWithString:self.model.sellerModel.consultingStar fontSize:12 andHeight:36] + 70;
        self.bubbleView = [[IMBottomBubbleView alloc] initWithFrame:CGRectZero];
        [self.bubbleView.bubble setTitle:self.model.sellerModel.consultingStar forState:UIControlStateNormal];
        
        [self.view addSubview:self.bubbleView];
        [self.bubbleView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(20);
            make.height.mas_equalTo(45);
            make.width.mas_equalTo(width);
            make.bottom.mas_equalTo(self.bottomView.mas_top);
        }];
        
        [self.view layoutIfNeeded];
    } else {
        self.bubbleView.hidden = YES;
    }
    
    [self.naviView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(0);
        make.height.mas_equalTo(kStatusBarHeight + NavBar_Height);
    }];
    
    [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.right.mas_equalTo(0);
        make.height.mas_equalTo(60 + Bottom_SafeHeight);
    }];
    
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.bottom.mas_equalTo(self.bottomView.mas_top);
    }];
    
    [self initViewAction];
}

- (void)initViewAction {
    WEAKSELF
    
    self.bubbleView.IMBottomBubbleViewBlock = ^(BubbleActionType type) {
        switch (type) {
            case BubbleActionType_close:{
                [weakSelf.bubbleView removeFromSuperview];
            } break;
            case BubbleActionType_jump:{
                [[TT_IMContactManager manager] ImContactWithStoreId:weakSelf.model.sellerModel.sellerId];
            } break;
            default:
                break;
        }
    };
    
    self.naviView.PackageDetailNaviViewBlock = ^(PackageDetailNaviViewActionType actionType) {
        
        switch (actionType) {
            case PackageDetailNaviViewActionType_back:{
                [weakSelf goBack];
            } break;
            case PackageDetailNaviViewActionType_collect:{

                [[BA_BusinessHelper shared] callCollectStoreWith:weakSelf.packageId
                                                   currentStatus:weakSelf.model.isCollect
                                                            type:BusinessCollectType_package
                                                        comption:^(BOOL success) {
                    weakSelf.model.isCollect = !weakSelf.model.isCollect;
                    [weakSelf.naviView refreshNaviFavorStatusWith:weakSelf.model.isCollect];
                }];

            } break;
            case PackageDetailNaviViewActionType_im:{
                MessageCenterViewController *vc = [[MessageCenterViewController alloc] init];
                [weakSelf.navigationController pushViewController:vc animated:YES];
            } break;
            case PackageDetailNaviViewActionType_share:{
                [weakSelf openLoginWithCompletion:^(BOOL isLogin, NSDictionary * _Nonnull options) {
                    if (isLogin) {
                        [weakSelf share];
                    }
                }];
            } break;
            default:
                break;
        }
    };
    
    self.naviView.PackageDetailSegBlock = ^(SegmentPackageDetailSelType type) {
        [weakSelf scrollCollectionWithType:type];
    };
    
    self.bottomView.WeddingCarDetailBottomViewBlock = ^(WeddingCarDetailBottomActionType actionType) {
        switch (actionType) {
            case WeddingCarDetailBottomActionType_im: {
                [[TT_IMContactManager manager] ImContactWithStoreId:weakSelf.model.sellerModel.sellerId];
            } break;
            case WeddingCarDetailBottomActionType_phone: {
                [[TT_PhonaCallManager manager] callWithStoreId:weakSelf.model.sellerModel.sellerId];
            } break;
            case WeddingCarDetailBottomActionType_yuyue: {
                [[BA_BusinessHelper shared] callSubscribeStoreWith:weakSelf.model.sellerModel.sellerId];
            } break;
            case WeddingCarDetailBottomActionType_cart: {
                
                WeddingCarCartViewController *vc = [[WeddingCarCartViewController alloc] init];
                vc.storeId = weakSelf.model.sellerModel.sellerId;
                [weakSelf.navigationController pushViewController:vc animated:YES];
                
            } break;
            case WeddingCarDetailBottomActionType_buy: {
                if (!weakSelf.selModel) {
                    [weakSelf showSKUWithType:PackageSKUViewActionType_buy];
                } else {
                    [weakSelf goBuy];
                }
            } break;
            default:
                break;
        }
    };
    
    //等待联调后数据确定sku交互
    self.skuView.PackageSKUViewBlock = ^(PackageSKUViewActionType type, WeddingCarSpecModel * _Nonnull selModel) {
      
        weakSelf.selModel = selModel;
        switch (type) {
            case PackageSKUViewActionType_none:{
                [weakSelf.collectionView reloadData];
            } break;
            case PackageSKUViewActionType_close:{
                [weakSelf.popView dismiss];
            } break;
            case PackageSKUViewActionType_cart:{
                [weakSelf request_AddCart];
                [weakSelf.popView dismiss];
            } break;
            case PackageSKUViewActionType_buy:{
                [weakSelf goBuy];
                [weakSelf.popView dismiss];
            } break;
            default:
                break;
        }
    };

}

- (void)goBuy {
    
    if ([TTUserModel sharedObject].token.length > 0) {
        NSMutableArray <WeddingCarCartModel *>*array = @[].mutableCopy;
        
        self.handleModel.goodsId = self.model.sellerGoodsModel.goodsId;
        self.handleModel.goodsMold = self.model.sellerGoodsModel.goodsMold;
        
        self.handleModel.sellerId = self.model.sellerModel.sellerId;
        self.handleModel.sellerName = self.model.sellerModel.sellerName;

        self.handleModel.specImg = self.selModel.specImage;
        self.handleModel.sgcsId = self.selModel.sgcsId;
        self.handleModel.specName = self.selModel.specName;
        self.handleModel.followPrice = self.selModel.followCarPrice;
        self.handleModel.goodsNum =  self.selModel.followCarNum;
        self.handleModel.platformPrice = self.selModel.platformPrice;
        
        self.handleModel.totalPrice = self.selModel.totalPrice;
        self.handleModel.userShoppingCarDetailList = self.selModel.userShoppingCarDetailList ;
        
        [array addObject:self.handleModel];
        SubmitCarOrderViewController *vc = [[SubmitCarOrderViewController alloc]init];
        vc.dataArray = array.mutableCopy;
        [self.navigationController pushViewController:vc animated:YES];
    } else {
        
        [self openLoginWithCompletion:^(BOOL isLogin, NSDictionary * _Nonnull options) {}];
    }
    
}

- (void)goBack {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark SKU Module
- (void)showSKUWithType:(PackageSKUViewActionType)type {



    self.popView = [LSTPopView initWithCustomView:self.skuView
                                                popStyle:LSTPopStyleSmoothFromBottom
                                            dismissStyle:LSTDismissStyleSmoothToBottom];
    self.popView.hemStyle = LSTHemStyleBottom;

    WEAKSELF
    self.popView.popDuration = 0.5;
    self.popView.dismissDuration = 0.5;
    self.popView.isClickFeedback = YES;
    self.popView.bgClickBlock = ^{
        [weakSelf.popView dismiss];
    };

    [self.popView pop];
}


#pragma mark Share
- (void)share {
    CommonShareModel *model = [[CommonShareModel alloc] init];
    model.url = [NSString stringWithFormat:@"%@%@?goodsId=%@&myCode=%@",BA_GlobalH5_Domain,@"/weddingCarShare",self.packageId,[TTUserModel sharedObject].myCode];
    model.title = self.model.sellerGoodsModel.goodsName;
    model.content = @"婚前婚后邀您体验";
    model.image = self.model.bannerPics.firstObject;
    [[TT_ShareManager share] callShareViewWithModel:model];
}


- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    UICollectionViewLayoutAttributes *serviceAttributes = [self.collectionView layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:WeddingCarDetailSectionType_service]];
    CGRect rect = serviceAttributes.frame;
    self.model.detail_y = rect.origin.y - kStatusBarHeight - NavBar_Height - 50;
    
    UICollectionViewLayoutAttributes *quanyiAttributes = [self.collectionView layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:WeddingCarDetailSectionType_quanyi]];
    CGRect quanyiRect = quanyiAttributes.frame;
    self.model.quanyi_y = quanyiRect.origin.y - kStatusBarHeight - NavBar_Height;
    
    if (scrollView.tag !=10086) {
        return;
    }
    
    CGFloat naviH = self.model.detail_y;
    //    导航栏设置
    CGFloat height = (300 - kStatusBarHeight - NavBar_Height);
    
    CGFloat alpha = scrollView.contentOffset.y/height;
    if (scrollView.contentOffset.y > 0.9 * height) {
        [self.naviView fillWithNaviStatus:GoodsNaviViewStatusType_white isCollect:self.model.isCollect alpha:alpha];
    } else {
        [self.naviView fillWithNaviStatus:GoodsNaviViewStatusType_clear isCollect:self.model.isCollect alpha:alpha];
    }
    
    [self refreshNaviWith:scrollView.contentOffset.y];
}

- (void)refreshNaviWith:(CGFloat)offset_y {
    if (offset_y >=self.model.package_y && offset_y < self.model.eva_y-1) {
        [self.naviView fillWithSegType:SegmentPackageDetailSelType_package];
    } else if (offset_y >=self.model.eva_y-1 && offset_y < self.model.detail_y-1) {
        [self.naviView fillWithSegType:SegmentPackageDetailSelType_evaluate];
    } else if (offset_y >=self.model.detail_y-1 && offset_y < self.model.quanyi_y-1){
        [self.naviView fillWithSegType:SegmentPackageDetailSelType_Detail];
    } else if (offset_y >=self.model.quanyi_y-1){
        [self.naviView fillWithSegType:SegmentPackageDetailSelType_Quanyi];
    }
}

- (void)scrollCollectionWithType:(SegmentPackageDetailSelType)type {
    CGFloat y=0;
    switch (type) {
        case SegmentPackageDetailSelType_package:{
            y = self.model.package_y;
        } break;
        case SegmentPackageDetailSelType_evaluate:{
            y = self.model.eva_y;
        } break;
        case SegmentPackageDetailSelType_Detail:{
            y = self.model.detail_y;
        } break;
        case SegmentPackageDetailSelType_Quanyi:{
            y = self.model.quanyi_y;
        } break;

        default:
            break;
    }
    
    NSLog(@"scrollCollectionWithType = %lf",y);
    [self.collectionView setContentOffset:CGPointMake(0, y) animated:YES];
    self.collectionView.bouncesZoom = NO;
}

#pragma mark- 协议方法
//collectionView的协议方法
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 8;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    switch (section) {
        case WeddingCarDetailSectionType_info:{
            return 7;
        } break;
        case WeddingCarDetailSectionType_evaTag:{
            return 0;
        } break;
        case WeddingCarDetailSectionType_eva:{
            return 0;
        } break;
        case WeddingCarDetailSectionType_storeInfo:{
            return 1;
        } break;
        case WeddingCarDetailSectionType_storeRec:{
            
            if (self.model.sellerGoodsList.count>4) {
                return 4;
            } else {
                return self.model.sellerGoodsList.count;
            }
            
        } break;
        case WeddingCarDetailSectionType_service:{
            return 1;
        } break;
        case WeddingCarDetailSectionType_imageAndText:{
            return 1;
        } break;
        case WeddingCarDetailSectionType_quanyi:{
            return 1;
        } break;
            
        default:
            break;
    }
    return 0;
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
        
    WEAKSELF
    if (kind == UICollectionElementKindSectionHeader) {
        
        switch (indexPath.section) {
            case WeddingCarDetailSectionType_info:{
            } break;
            case WeddingCarDetailSectionType_evaTag:{

                WeddingCarDetailSectionView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"WeddingCarDetailSectionView" forIndexPath:indexPath];
                headerView.sectionTitle.text = @"用户评价";
                headerView.bgImageView.hidden = YES;
                headerView.sectionSubTitle.text = @"查看全部>";
                
                [headerView addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {

                    EvaluateListViewController *vc = [[EvaluateListViewController alloc] init];
                    vc.storeId = weakSelf.model.sellerModel.sellerId;
                    [weakSelf.navigationController pushViewController:vc animated:YES];

                }];
                
                return headerView;
                
            } break;
            case WeddingCarDetailSectionType_eva:{

                ProductDetailEvaluationHeader *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailEvaluationHeader" forIndexPath:indexPath];
                
                if (self.model.evaluateArray.count > 0) {
                    [headerView fillHeadWithModel:self.model.evaluateArray[0]];
                }
                
                WEAKSELF
                [headerView addGestureTapEventHandle:^(id  _Nonnull sender, UITapGestureRecognizer * _Nonnull gestureRecognizer) {
                   
                    EvaluationDetailViewController *vc = [[EvaluationDetailViewController alloc] init];
                    vc.ueId = weakSelf.model.evaluateArray.firstObject.ueId;
                    [weakSelf.navigationController pushViewController:vc animated:YES];
                }];
                
                return headerView;
                
            } break;
            case WeddingCarDetailSectionType_storeInfo:{
            } break;
            case WeddingCarDetailSectionType_storeRec:{
                
                ProductDetailNormalSectionView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailNormalSectionView" forIndexPath:indexPath];
                headerView.sectionTitle.text = @"店铺推荐";
                headerView.sectionTitle.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
                headerView.sectionSubTitle.text = @"";
                headerView.bgImageView.hidden = YES;
                headerView.titleLeadConstrain.constant = 14;
                return headerView;
                
            } break;
            case WeddingCarDetailSectionType_service:{

                ProductDetailNormalSectionView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailNormalSectionView" forIndexPath:indexPath];
                headerView.sectionTitle.text = @"服务内容";
                headerView.sectionTitle.font = [UIFont systemFontOfSize:14 weight:UIFontWeightSemibold];
                headerView.sectionSubTitle.text = @"";
//                headerView.bgImageView.hidden = YES;
                headerView.titleLeadConstrain.constant = 14;
                headerView.topDistanceConstrain.constant = CGFLOAT_MIN;
                return headerView;
                
            } break;
            case WeddingCarDetailSectionType_imageAndText:{
                
                ProductDetailNormalSectionView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailNormalSectionView" forIndexPath:indexPath];
                headerView.sectionTitle.text = @"图文介绍";
                headerView.sectionTitle.font = [UIFont systemFontOfSize:14 weight:UIFontWeightSemibold];
                headerView.sectionSubTitle.text = @"";
//                headerView.bgImageView.hidden = YES;
                headerView.titleLeadConstrain.constant = 14;
                headerView.topDistanceConstrain.constant = CGFLOAT_MIN;
                return headerView;
                
            } break;
            case WeddingCarDetailSectionType_quanyi:{

                PackageDetailSectionHeader *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"PackageDetailSectionHeader" forIndexPath:indexPath];
                headerView.sectionTitleLab.text = @"平台权益";
                
                return headerView;

            } break;
            default:
                break;
        }

        ProductDetailNormalSectionView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailNormalSectionView" forIndexPath:indexPath];

        return footerView;
        
    } else {
        
        if (indexPath.section == WeddingCarDetailSectionType_storeRec) {
            
            PackageDetailSectionHeader *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"PackageDetailSectionHeader" forIndexPath:indexPath];
            headerView.sectionTitleLab.text = @"婚车详情";
            
            return headerView;
        }
        
        
        ProductDetailSectionFooterView *footerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ProductDetailSectionFooterView" forIndexPath:indexPath];

        return footerView;
    }
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {

    switch (indexPath.section) {
        case WeddingCarDetailSectionType_info:{
            switch (indexPath.row) {
                    
                case WeddingCarInfoCellType_explain:{
                    
//                    PromisePopViewController *pop = [[PromisePopViewController alloc]initDefaultHeight:0.6*TTScreenHeight vc:self dataSource:@[].mutableCopy];
//                    STPopupController *popVericodeController = [[STPopupController alloc] initWithRootViewController:pop];
//                    popVericodeController.style = STPopupStyleBottomSheet;
//                    [popVericodeController presentInViewController:self];
                    WYXViewController *vc = [[WYXViewController alloc] init];
                    vc.storeId = self.model.sellerModel.sellerId;
                    [self.navigationController pushViewController:vc animated:YES];
                    
                } break;
                case WeddingCarInfoCellType_info:{
                    
                } break;
                case WeddingCarInfoCellType_sku:{
                    [self showSKUWithType:PackageSKUViewActionType_buy];
                } break;
                case WeddingCarInfoCellType_intentionGift:{
                    [self showSKUWithType:PackageSKUViewActionType_buy];
                } break;
                case WeddingCarInfoCellType_orderGift:{
                    [self showSKUWithType:PackageSKUViewActionType_buy];
                } break;
                default:
                    break;
            }
        } break;
        case WeddingCarDetailSectionType_evaTag:{
        } break;
        case WeddingCarDetailSectionType_eva:{
        } break;
        case WeddingCarDetailSectionType_storeInfo:{

            StoreDetailViewController *vc = [[StoreDetailViewController alloc] init];
            vc.storeId = self.model.sellerModel.sellerId;
            [self.navigationController pushViewController:vc animated:YES];
        } break;
        case WeddingCarDetailSectionType_storeRec:{

            CommonPackageModel *model = self.model.sellerGoodsList[indexPath.row];
            [[TT_JumpManager sharedManager] jumpWithDetailModel:model completion:^(BOOL success, NSString * _Nonnull message) {}];


        } break;
        case WeddingCarDetailSectionType_imageAndText:{
        } break;
        default:
            break;
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
        
    WEAKSELF
    switch (indexPath.section) {
        case WeddingCarDetailSectionType_info:{

            switch (indexPath.row) {
                    
                case WeddingCarInfoCellType_banner: {
                    self.mediaCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PackageDetailBannerCellID" forIndexPath:indexPath];
                                        
                    NSString *maskUrl = @"";
                    if (self.model.videofengmianList.count > 0) {
                        maskUrl =self.model.videofengmianList.firstObject.url;
                    }
                    [self.mediaCell fillWithImgArray:self.model.bannerPics videoUrl:self.model.videoUrl andMaskUrl:maskUrl];
                    
                    self.mediaCell.bannerIndexClicked = ^(NSInteger index) {
                        
                        if (weakSelf.model.bannerPics.count > 0) {
//                            [weakSelf showImageWithArray:weakSelf.model.bannerPics index:index];
                        }
                    };
                    
                    return self.mediaCell;
                } break;
                case WeddingCarInfoCellType_explain:{

                    WeddingCarDetailServiceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WeddingCarDetailServiceCellID" forIndexPath:indexPath];
                    [cell fillHeaderWithModel:self.model];
                    return cell;
                    
                } break;
                case WeddingCarInfoCellType_info:{
                    
                    WeddingCarDetailInfoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WeddingCarDetailInfoCellID" forIndexPath:indexPath];
                    [cell fillCellWithModel:self.model.sellerGoodsModel];
                    return cell;
                    
                } break;
                case WeddingCarInfoCellType_sku:{
                    
                    WeddingCarDetailSKUCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WeddingCarDetailSKUCellID" forIndexPath:indexPath];
                    [cell fillCellWithModel:self.model.sellerGoodsModel];
                    
                    
                    return cell;
                    
                } break;
                case WeddingCarInfoCellType_intentionGift:{

                    PackageDetailInfoShowCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PackageDetailInfoShowCellID" forIndexPath:indexPath];
                    cell.titleLab.text = @"意向礼";
                    cell.subTitleLab.text = self.model.sellerGoodsModel.goodsDepositGift;
                    cell.cacheLab.text = @"去下单";
                    cell.cacheLab.textColor = UIColorHex(0xF78E2E);
                    cell.lineView.hidden = NO;
                    return cell;
                    
                } break;
                case WeddingCarInfoCellType_orderGift:{

                    PackageDetailInfoShowCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PackageDetailInfoShowCellID" forIndexPath:indexPath];
                    cell.titleLab.text = @"全款礼";
                    cell.subTitleLab.text = self.model.sellerGoodsModel.goodsTotalGift;
                    cell.cacheLab.text = @"去下单";
                    cell.cacheLab.textColor = UIColorHex(0xF78E2E);
                    cell.lineView.hidden = NO;
                    return cell;
                    
                } break;
                case WeddingCarInfoCellType_orderStep:{

                    WeddingCarDetailStepCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WeddingCarDetailStepCellID" forIndexPath:indexPath];
                    return cell;
                    
                } break;
                default:
                    break;
            }
            
        } break;
        case WeddingCarDetailSectionType_evaTag:{
            
        } break;
        case WeddingCarDetailSectionType_eva:{
            
        } break;
        case WeddingCarDetailSectionType_storeInfo:{

            PackageDetailStoreInfoCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"PackageDetailStoreInfoCellID" forIndexPath:indexPath];
            [cell fillCellWithModel:self.model];
            
            cell.PackageDetailStoreInfoCellBlock = ^{
              
                WYXViewController *vc = [[WYXViewController alloc] init];
                vc.storeId = weakSelf.model.sellerModel.sellerId;
                [weakSelf.navigationController pushViewController:vc animated:YES];
            };
            return cell;
            
        } break;
        case WeddingCarDetailSectionType_storeRec:{

            WeddingCarDetailRecCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WeddingCarDetailRecCellID" forIndexPath:indexPath];
            
            if (self.model.sellerGoodsList.count > indexPath.row) {
                [cell fillCellWithModel:self.model.sellerGoodsList[indexPath.row]];
            }
            
            return cell;
            
        } break;
        case WeddingCarDetailSectionType_service:{

            self.serviceCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cid" forIndexPath:indexPath];
            [self.serviceCell addSubview:self.serviceVC.view];
            [self.serviceVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.right.bottom.mas_equalTo(0);
            }];
            return self.serviceCell;
            
        } break;
        case WeddingCarDetailSectionType_imageAndText:{

            self.imageTextCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cid" forIndexPath:indexPath];
            [self.imageTextCell addSubview:self.imageTextVC.view];
            [self.imageTextVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.right.bottom.mas_equalTo(0);
            }];
            return self.imageTextCell;
            
        } break;
        case WeddingCarDetailSectionType_quanyi:{

            self.quanyiCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cid" forIndexPath:indexPath];
            [self.quanyiCell addSubview:self.quanyiVC.view];
            [self.quanyiVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.top.right.bottom.mas_equalTo(0);
            }];
            return self.quanyiCell;

        } break;
        default:
            break;
    }

    WeddingCarDetailServiceCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"WeddingCarDetailServiceCellID" forIndexPath:indexPath];
    return cell;
}

//ZZLyout的流协议方法
- (CGFloat)layout:(ZZLayout *)layout heightForRowAtIndexPath:(NSIndexPath *)indexPath {//返回item的高
    
//    WEAKSELF
    switch (indexPath.section) {
        case WeddingCarDetailSectionType_info:{

            switch (indexPath.row) {
                    
                case WeddingCarInfoCellType_banner: {
                    return [PackageDetailBannerCell calculateHeight];;
                } break;
                case WeddingCarInfoCellType_info:{
                    return  [WeddingCarDetailInfoCell calculateHeightWithModel:self.model.sellerGoodsModel];
                } break;
                case WeddingCarInfoCellType_sku:{
                    return [WeddingCarDetailSKUCell calculateHeight];
                } break;
                case WeddingCarInfoCellType_explain:{
                    
                    if (self.model.sellerModel.examStatus == 2) {
                        return  [WeddingCarDetailServiceCell calculateHeight];
                    } else {
                        return CGFLOAT_MIN;
                    }

                } break;
                case WeddingCarInfoCellType_intentionGift:{
                    return [PackageDetailInfoShowCell calculateHeight];
                } break;
                case WeddingCarInfoCellType_orderGift:{
//                    if (self.model.sellerGoodsModel.goodsDepositGift.length > 0) {
                        return [PackageDetailInfoShowCell calculateHeight];
//                    }
                } break;
                case WeddingCarInfoCellType_orderStep:{
                    return [WeddingCarDetailStepCell calculateHeight];
                } break;
                default:
                    break;
            }
            
        } break;
        case WeddingCarDetailSectionType_evaTag:{
            return CGFLOAT_MIN;
        } break;
        case WeddingCarDetailSectionType_eva:{
            return CGFLOAT_MIN;
        } break;
        case WeddingCarDetailSectionType_storeInfo:{
//            CGFloat height = [PackageDetailStoreInfoCell calculateHeightWithModel:self.model];
            return CGFLOAT_MIN;
        } break;
        case WeddingCarDetailSectionType_storeRec:{
            return [WeddingCarDetailRecCell calculateHeight];
        } break;
        case WeddingCarDetailSectionType_service:{
            return self.serviceHeight;
        } break;
        case WeddingCarDetailSectionType_imageAndText:{
            return self.imageTextHeight;
        } break;
        case WeddingCarDetailSectionType_quanyi:{
            return TTScreenWidth * 2.91466 + 50;
        } break;
        default:
            break;
    }

    return CGFLOAT_MIN;
}

- (NSInteger)layout:(ZZLayout *)layout columnNumberAtSection:(NSInteger)section {//每个区有几列
    
    switch (section) {
        case WeddingCarDetailSectionType_info:{
            return 1;
        } break;
        case WeddingCarDetailSectionType_evaTag:{
            return 1;
        } break;
        case WeddingCarDetailSectionType_eva:{
            return 1;
        } break;
        case WeddingCarDetailSectionType_storeInfo:{
            return 1;
        } break;
        case WeddingCarDetailSectionType_storeRec:{
            return 2;
        } break;
        case WeddingCarDetailSectionType_service:{
            return 1;
        } break;
        case WeddingCarDetailSectionType_imageAndText:{
            return 1;
        } break;
        case WeddingCarDetailSectionType_quanyi:{
            return 1;
        }
        default:
            break;
    }
    return 0;
}

- (UIEdgeInsets)layout:(ZZLayout *)layout insetForSectionAtIndex:(NSInteger)section {//设置每个区的边距
    
    switch (section) {
        case WeddingCarDetailSectionType_info:{
            return UIEdgeInsetsMake(0, 0, 0, 0);
        } break;
        case WeddingCarDetailSectionType_evaTag:{
            return UIEdgeInsetsMake(0, 0, 0, 0);
        } break;
        case WeddingCarDetailSectionType_eva:{
            return UIEdgeInsetsMake(0, 0, 0, 0);
        } break;
        case WeddingCarDetailSectionType_storeInfo:{
            return UIEdgeInsetsMake(0, 0, 0, 0);
        } break;
        case WeddingCarDetailSectionType_storeRec:{
            if (self.model.sellerGoodsList.count > 0) {
                return UIEdgeInsetsMake(15, 15, 15, 15);
            } else {
                return UIEdgeInsetsMake(0, 0, 0, 0);
            }
        } break;
        case WeddingCarDetailSectionType_service:{
            return UIEdgeInsetsMake(0, 0, 0, 0);
        } break;
        case WeddingCarDetailSectionType_imageAndText:{
            return UIEdgeInsetsMake(0, 0, 0, 0);
        } break;
        case WeddingCarDetailSectionType_quanyi:{
            return UIEdgeInsetsMake(0, 0, 0, 0);
        }
        default:
            break;
    }
    
    return UIEdgeInsetsMake(0, 0, 0, 0);
}

- (NSInteger)layout:(ZZLayout *)layout lineSpacingForSectionAtIndex:(NSInteger)section {//设置每个区的行间距

    switch (section) {
        case WeddingCarDetailSectionType_info:{
        } break;
        case WeddingCarDetailSectionType_evaTag:{
        } break;
        case WeddingCarDetailSectionType_eva:{
        } break;
        case WeddingCarDetailSectionType_storeInfo:{
        } break;
        case WeddingCarDetailSectionType_storeRec:{
            if (self.model.sellerGoodsList.count > 0) {
                return 10;
            }
        } break;
        case WeddingCarDetailSectionType_service:{
        } break;
        case WeddingCarDetailSectionType_imageAndText:{
        } break;
        case WeddingCarDetailSectionType_quanyi:{
        }
        default:
            break;
    }
    
    return 0;
}

- (CGFloat)layout:(ZZLayout*)layout interitemSpacingForSectionAtIndex:(NSInteger)section {//设置每个区的列间距

    switch (section) {
        case WeddingCarDetailSectionType_info:{
            return 1;
        } break;
        case WeddingCarDetailSectionType_evaTag:{
        } break;
        case WeddingCarDetailSectionType_eva:{
        } break;
        case WeddingCarDetailSectionType_storeInfo:{
        } break;
        case WeddingCarDetailSectionType_storeRec:{
            
            if (self.model.sellerGoodsList.count > 0) {
                return 10;
            }
            
        } break;
        case WeddingCarDetailSectionType_service:{
        } break;
        case WeddingCarDetailSectionType_imageAndText:{
        } break;
        case WeddingCarDetailSectionType_quanyi:{
        }
        default:
            break;
    }
    return CGFLOAT_MIN;
}

- (CGSize)layout:(ZZLayout *)layout referenceSizeForHeaderInSection:(NSInteger)section {//设置区头的高度
    
    switch (section) {
        case WeddingCarDetailSectionType_info:{
            
        } break;
        case WeddingCarDetailSectionType_evaTag:{

            if (self.model.evaluateArray.count > 0) {
                return CGSizeMake(TTScreenWidth, [ProductDetailNormalSectionView calculateHeight]);
            } else {
                return CGSizeMake(TTScreenWidth, CGFLOAT_MIN);
            }

        } break;
        case WeddingCarDetailSectionType_eva:{

            if (self.model.evaluateArray.count > 0) {
                return CGSizeMake(TTScreenWidth, self.model.evaluateArray.firstObject.itemHeight);
            } else {
                return CGSizeMake(TTScreenWidth, CGFLOAT_MIN);
            }
            
        } break;
        case WeddingCarDetailSectionType_storeInfo:{

        } break;
        case WeddingCarDetailSectionType_storeRec:{

            if (self.model.sellerGoodsList.count > 0) {
                return CGSizeMake(TTScreenWidth, [ProductDetailNormalSectionView calculateHeight]);
            } else {
                return CGSizeMake(TTScreenWidth, CGFLOAT_MIN);
            }
        } break;
        case WeddingCarDetailSectionType_service:{
            return CGSizeMake(TTScreenWidth, [ProductDetailNormalSectionView calculateHeight]);
        } break;
        case WeddingCarDetailSectionType_imageAndText:{
            return CGSizeMake(TTScreenWidth, [ProductDetailNormalSectionView calculateHeight]);

        } break;
        case WeddingCarDetailSectionType_quanyi:{
            return CGSizeMake(TTScreenWidth, CGFLOAT_MIN);
        } break;
        default:
            break;
    }
    
    return CGSizeMake(TTScreenWidth, CGFLOAT_MIN);
}

- (CGSize)layout:(ZZLayout *)layout referenceSizeForFooterInSection:(NSInteger)section {//设置区尾的高度
    
    if (section == WeddingCarDetailSectionType_storeRec) {
        return CGSizeMake(TTScreenWidth, [PackageDetailSectionHeader calculateHeight]);
    }

    return CGSizeMake(TTScreenWidth, CGFLOAT_MIN);
}

- (CGFloat)layout:(ZZLayout*)layout spacingWithLastSectionForSectionAtIndex:(NSInteger)section {//本区区头和上个区区尾的间距
    return 0;
}

- (UIColor *)layout:(UICollectionView *)layout colorForSection:(NSInteger)section {//设置不同分区的不同背景颜色
    return UIColorHex(0xffffff);
}

- (PackageSKUView *)skuView {
    if (!_skuView) {
        _skuView = [[NSBundle mainBundle] loadNibNamed:@"PackageSKUView" owner:nil options:nil].firstObject;
    }
    return _skuView;
}

- (ImageTextTableViewController *)imageTextVC {
    if (!_imageTextVC) {
        _imageTextVC = [[ImageTextTableViewController alloc] init];
        _imageTextVC.model = self.model;
        
        WEAKSELF
        [RACObserve(_imageTextVC.tableview, contentSize) subscribeNext:^(id x) {
            weakSelf.imageTextHeight = weakSelf.imageTextVC.tableview.contentSize.height;
            [weakSelf.collectionView reloadData];
        }];
    }
    return _imageTextVC;
}

- (ServiceContentViewController *)serviceVC {
    if (!_serviceVC) {
        _serviceVC = [[ServiceContentViewController alloc] init];
        _serviceVC.model = self.model;
        
        WEAKSELF
        [RACObserve(_serviceVC.collectionView, contentSize) subscribeNext:^(id x) {
            weakSelf.serviceHeight = weakSelf.serviceVC.collectionView.contentSize.height;
            [weakSelf.collectionView reloadData];
        }];
    }
    return _serviceVC;
}

- (QuanYiViewController *)quanyiVC {
    if (!_quanyiVC) {
        _quanyiVC = [[QuanYiViewController alloc] init];
//        WEAKSELF
//        [RACObserve(_quanyiVC.tableview, contentSize) subscribeNext:^(id x) {
//            weakSelf.quanyiHeight = weakSelf.quanyiVC.tableview.contentSize.height;
//            [weakSelf.collectionView reloadData];
//        }];
    }
    return _quanyiVC;
}

- (PackageDetailModule *)model {
    if (!_model) {
        _model = [[PackageDetailModule alloc] init];
    }
    return _model;
}

- (WeddingCarDetailBottomView *)bottomView {
    if (!_bottomView) {
        _bottomView = [[NSBundle mainBundle] loadNibNamed:@"WeddingCarDetailBottomView"owner:nil options:nil].firstObject;
    }
    return _bottomView;
}

- (PackageDetailNaviView *)naviView {
    if (!_naviView) {
        _naviView = [[NSBundle mainBundle] loadNibNamed:@"PackageDetailNaviView"owner:nil options:nil].firstObject;
    }
    return _naviView;
}

- (WeddingCarCartModel *)handleModel {
    if (!_handleModel) {
        _handleModel = [[WeddingCarCartModel alloc] init];
    }
    return _handleModel;
}

#pragma mark- 懒加载
- (UICollectionView *)collectionView {
    if (!_collectionView) {
        
        ZZLayout *layout = [[ZZLayout alloc] initWith:ZZLayoutFlowTypeVertical delegate:self];
        //打开区头悬浮功能(默认关闭)
        layout.sectionHeadersPinToVisibleBounds = NO;
        
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
        _collectionView.backgroundColor = UIColorHex(0xf1f1f1);
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.tag = 10086;
        
        [_collectionView registerClass:[PackageDetailBannerCell class] forCellWithReuseIdentifier:@"PackageDetailBannerCellID"];

        [_collectionView registerNib:[UINib nibWithNibName:@"WeddingCarDetailInfoCell" bundle:nil] forCellWithReuseIdentifier:@"WeddingCarDetailInfoCellID"];
        [_collectionView registerNib:[UINib nibWithNibName:@"WeddingCarDetailSKUCell" bundle:nil] forCellWithReuseIdentifier:@"WeddingCarDetailSKUCellID"];

        
        [_collectionView registerNib:[UINib nibWithNibName:@"PackageDetailInfoShowCell" bundle:nil] forCellWithReuseIdentifier:@"PackageDetailInfoShowCellID"];
        [_collectionView registerNib:[UINib nibWithNibName:@"PackageDetailStoreInfoCell" bundle:nil] forCellWithReuseIdentifier:@"PackageDetailStoreInfoCellID"];
        [_collectionView registerNib:[UINib nibWithNibName:@"WeddingCarDetailRecCell" bundle:nil] forCellWithReuseIdentifier:@"WeddingCarDetailRecCellID"];
        [_collectionView registerNib:[UINib nibWithNibName:@"WeddingCarDetailStepCell" bundle:nil] forCellWithReuseIdentifier:@"WeddingCarDetailStepCellID"];
        [_collectionView registerNib:[UINib nibWithNibName:@"WeddingCarDetailServiceCell" bundle:nil] forCellWithReuseIdentifier:@"WeddingCarDetailServiceCellID"];
        
        [_collectionView registerNib:[UINib nibWithNibName:@"ProductDetailNormalSectionView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailNormalSectionView"];
        
        [_collectionView registerNib:[UINib nibWithNibName:@"WeddingCarDetailSectionView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"WeddingCarDetailSectionView"];
        
        [_collectionView registerNib:[UINib nibWithNibName:@"PackageDetailSectionHeader" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"PackageDetailSectionHeader"];
        
        [_collectionView registerNib:[UINib nibWithNibName:@"ProductDetailEvaluationHeader" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"ProductDetailEvaluationHeader"];
        
        [_collectionView registerNib:[UINib nibWithNibName:@"ProductDetailSectionFooterView" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"ProductDetailSectionFooterView"];
        
        [_collectionView registerNib:[UINib nibWithNibName:@"PackageDetailSectionHeader" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"PackageDetailSectionHeader"];

        
        [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cid"];
        
        _collectionView.showsHorizontalScrollIndicator = NO;
        _collectionView.showsVerticalScrollIndicator = NO;

        _collectionView.bounces = YES;
        self.edgesForExtendedLayout = UIRectEdgeNone;
        if (@available(iOS 11.0, *)) {
            _collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }
    }
    return _collectionView;
}

- (void)request_packageDetail {

    WEAKSELF
    [PackageDetailRequest request_packageDetailWith:self.packageId statistics:self.shouldStatistics comption:^(BOOL success, PackageDetailModule * _Nonnull model) {
            
        if (model.sellerGoodsModel.goodsStatus == 2) {
            [TT_Alert alert:@"该套餐已下架" doneAction:^{
                [weakSelf.navigationController popViewControllerAnimated:YES];
            }];
            return;
        }
        
        if (success) {
            weakSelf.model = model;
            [weakSelf initView];
            [weakSelf.collectionView reloadData];
            
            weakSelf.skuView.frame = CGRectMake(10, 10, TTScreenWidth,TTScreenHeight * 0.8);
            [weakSelf.skuView fillSkuViewWithModel:model.sellerGoodsModel Type:PackageSKUViewActionType_none];
            
            if ([TTUserModel sharedObject].userId.length > 0) {
                [weakSelf addQuickReply];
            }
            
            if ([TTUserModel sharedObject].userId.length > 0) {
                [[BA_BusinessHelper shared] browseStore:model.sellerModel.sellerId
                                                   type:BusinessActionType_tcs
                                               comption:^(BOOL success) {}];
            }

        }
    }];
}

- (void)request_AddCart {
    
    NSMutableDictionary *dic = @{}.mutableCopy;
    [dic setValue:[TTUserModel sharedObject].userId forKey:@"userId"];
    [dic setValue:self.model.sellerModel.sellerId forKey:@"sellerId"];
    [dic setValue:self.model.sellerGoodsModel.goodsMold forKey:@"goodsMold"];
    [dic setValue:self.packageId forKey:@"goodsId"];
    [dic setValue:self.selModel.sgcsId forKey:@"sgcsId"];
    [dic setValue:@(self.selModel.followCarNum) forKey:@"goodsNum"];
    
    NSString *url = [NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,API_AddCarCart];
    
    [SVProgressHUD showWithStatus:@"正在加载"];
    [TTHttpManager postRequestWithUrl:url TimeOut:10 PostData:dic FinishBlock:^(id  _Nonnull data) {
        
        [SVProgressHUD dismiss];
        if ([data isKindOfClass:[NSDictionary class]]) {
            //请求成功
            NSInteger code = [[data valueForKey:@"code"] integerValue];
            if (code == 10000) {

                [SVProgressHUD showSuccessWithStatus:[data valueForKey:@"message"]];
                [SVProgressHUD dismissWithDelay:1];
            } else {
                [SVProgressHUD showErrorWithStatus:[data valueForKey:@"message"]];
                [SVProgressHUD dismissWithDelay:1];
            }
        }
        
    } FailedBlock:^(NSError * _Nonnull error) {
        [SVProgressHUD dismiss];
    }];
}

#pragma mark - 快捷回复模块
- (void)addQuickReply
{
    dispatch_async(dispatch_get_main_queue(), ^{
        //获取快捷回复
        NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
        [parameters setValue:[NSString stringWithFormat:@"%@",self.model.sellerModel.sellerId] forKey:@"sellerId"];
        WK(weakSelf)
        [TTHttpManager postRequestWithUrl:[NSString stringWithFormat:@"%@%@",TT_Global_Api_Domain,@"/userProblem/userSelectList"] TimeOut:10 PostData:parameters FinishBlock:^(id  _Nonnull responseObject) {
            TIIMQuickReplyCardModel *responModel = [TIIMQuickReplyCardModel modelWithJSON:responseObject];
            if (responModel.success) {
                if (responModel.data.count > 0) {
                    weakSelf.quickReplyModel = responModel;
                    [weakSelf quickReplyButton];
                }
            } else {
                
            }
        } FailedBlock:^(NSError * _Nonnull error) {
            
        }];
    });
}
- (BaseAdjustButton *)quickReplyButton
{
    if (!_quickReplyButton) {
        BaseAdjustButton *button = [BaseAdjustButton buttonWithType:UIButtonTypeCustom];
        [self.view addSubview:button];
        button.type = layoutTypeHorizontalLeftImageRightTitle;
        button.imageWidth = 10*ADAPTER_WIDTH;
        button.imageHeight = 6*ADAPTER_WIDTH;
        button.title = @"快问";
        button.fontWeight = UIFontWeightMedium;
        button.fontSize = 13*ADAPTER_WIDTH;
        button.marginLeft = 10*ADAPTER_WIDTH;
        button.marginItemX = 4*ADAPTER_WIDTH;
        button.marginRight = 10*ADAPTER_WIDTH;
        button.marginTop = 10*ADAPTER_WIDTH;
        button.marginBottom = 10*ADAPTER_WIDTH;
        [button begin];
        button.right = WIDTH - 16*ADAPTER_WIDTH;
        button.bottom = HEIGHT - 150*ADAPTER_WIDTH - kBottomSafeHeight;
        button.backgroundColor = rgba(0, 0, 0, 0.8);
        button.backgroundColor = rgba(76, 198, 253, 1);
        [button setTitleColor:WhiteColor forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"QuickReply_up"] forState:UIControlStateNormal];
        [button setImage:[UIImage imageNamed:@"QuickReply_down"] forState:UIControlStateSelected];
        [button setTitle:@"快问" forState:UIControlStateNormal];
        [button setTitle:@"收起" forState:UIControlStateSelected];
        [button addTarget:self action:@selector(clickQuickReplyButton:) forControlEvents:UIControlEventTouchUpInside];
        button.layer.cornerRadius = button.height * 0.5;
        button.layer.masksToBounds = YES;
        _quickReplyButton = button;
    }
    return _quickReplyButton;
}

- (void)clickQuickReplyButton:(UIButton *)sender
{
    sender.selected = !sender.selected;
    if (sender.selected) {
        sender.backgroundColor = rgba(0, 0, 0, 0.8);
        [sender setImage:[UIImage imageNamed:@"QuickReply_dwon"] forState:UIControlStateNormal];
        
        StoreQuickReplyView *view = [[StoreQuickReplyView alloc]initWithFrame:CGRectZero withParent:self withReplyButton:sender];
        view.quickReplyModel = self.quickReplyModel;
        WK(weakSelf)
        [view setCallBackContentBlock:^(NSString * _Nonnull content) {
            [weakSelf gotoChatWithContent:content];
        }];
        self.weakQuickReplyView = view;
    } else {
        sender.backgroundColor = rgba(76, 198, 253, 1);
        [sender setImage:[UIImage imageNamed:@"QuickReply_up"] forState:UIControlStateNormal];
        if (_weakQuickReplyView) {
            [self.weakQuickReplyView dismiss];
        }
    }
}
- (void)gotoChatWithContent:(NSString *)content {
    [[TT_IMContactManager manager] ImContactWithStoreId:self.model.sellerModel.sellerId withQuickReply:content];
    
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    if (_quickReplyButton) {
        WK(weakSelf)
        [UIView animateWithDuration:0.2 animations:^{
            weakSelf.quickReplyButton.right = WIDTH - 16*ADAPTER_WIDTH;
        }];
    }
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
    if (_quickReplyButton) {
        WK(weakSelf)
        [UIView animateWithDuration:0.2 animations:^{
            weakSelf.quickReplyButton.right = WIDTH - 16*ADAPTER_WIDTH;
        }];
    }
}

@end
